﻿@using Sovigaz
@{
    ViewBag.Title = "Chi tiết kế hoạch giao hàng";
    var url = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/');
    var repository = new Sovigaz.Permission.Repositories.DeliveryPlanRepository();
    bool canEdit = repository.canEdit(Utilities.ConvertUtility.IntParse(Model));
}
<script>
    app.controller('DeliveryPlanController', function ($scope, $compile, $http, $filter, service) {

        $scope.loadPartner = function () {
            var url = '@url' + '@Url.Action("PartnerApi", "Api")';
            $http.get(url)
                .success(function (data) {
                    for (var i = 0; i < data.length; i++) {
                        $scope.partners[data[i].PartnerID]=data[i].PartnerName;
                        $scope.locations[data[i].PartnerID]=data[i].LocationName;
                    }                    
                })
                .error(function (data) {
                    service.showModal($scope, $compile, 'error', data);
                });
        };

        $scope.loadlicensePlate = function () {
            var url = '@url' + '@Url.Action("LicensePlateApi", "Api")';
            $http.get(url)
                .success(function (data) {
                    $scope.licensePlates.length=0;
                    $scope.licensePlates.push({"name":"-Select One-","value":0});
                    for (var i = 0; i < data.length; i++) {
                        $scope.licensePlates.push({"name":data[i].LicensePlateName,"value":data[i].LicensePlateID});      
                    }
                })
                .error(function (data) {
                    service.showModal($scope, $compile, 'error', data);
                });
        };

        $scope.loadTaiXe = function () {
            var url = '@url' + '@Url.Action("UserApi", "Api", new { positionID = "TX" })';
            $http.get(url)
                .success(function (data) {
                    $scope.users.length=0;
                    $scope.users.push({"name":"-Select One-","value":0});
                    for (var i = 0; i < data.length; i++) {
                        $scope.users.push({"name":data[i].FullName,"value":data[i].UserID});
                    }                    
                })
                .error(function (data) {
                    service.showModal($scope, $compile, 'error', data);
                });
        };

        $scope.loadBocXep = function () {
            var url = '@url' + '@Url.Action("UserApi", "Api", new { positionID = "BX" })';
            $http.get(url)
                .success(function (data) {
                    $scope.bocxeps.length=0;
                    $scope.bocxeps.push({"name":"-None-","value":0});
                    for (var i = 0; i < data.length; i++) {
                        $scope.bocxeps.push({"name":data[i].FullName,"value":data[i].UserID});
                    }                    
                })
                .error(function (data) {
                    service.showModal($scope, $compile, 'error', data);
                });
        };

        $scope.load = function () {
            startloading($('#content'));

            var url = '@url' + '@Url.Action("DeliveryPlanApi", "Api", new { id = Model })';

            $http.get(url)
                .success(function (data) {
                    $scope.deliveryPlan = data;
                    $scope.isDisabled = false;
                    if(data.Status=='I') $scope.isDisabled = true;
                    $scope.userID = { name: '', value: data.UserID };
                    $scope.bocxep1 = { name: '', value: data.BocXep1 };
                    $scope.bocxep2 = { name: '', value: data.BocXep2 };
                    $scope.bocxep3 = { name: '', value: data.BocXep3 };
                    $scope.licensePlate = {name:'', value:data.LicensePlate};
                    $scope.status = { name: '', value: data.Status };
                    $scope.deliveryPlan.Date = $filter('date')(Date.parse($scope.deliveryPlan.Date), 'y/MM/dd');
                    if(data.DeliveryType=="IN") $scope.deliverytype = true;

                    for (var i = 0; i < data.OrderLines.length; i++)     
                    {
                        $scope.temp[data.OrderLines[i].OrderLineID]=data.OrderLines[i].OrderID;
                        
                    }

                    $scope.orders.length=0;
                    for (var i = 0; i < data.Orders.length; i++) {  
                        var flag1 = false;
                        for(var j = 0; j< data.OrderLines.length; j++)
                            if(data.OrderLines[j].OrderID == data.Orders[i].OrderID)
                            {
                                var flag2 = false;
                                for(var k = 0; k < data.DeliveryPlanLines.length; k++)
                                    if(data.DeliveryPlanLines[k].OrderLineID == data.OrderLines[j].OrderLineID) 
                                    {
                                        flag2 = true;
                                        break;
                                    }
                                if(!flag2)
                                {
                                    flag1 = true;
                                    break;
                                }
                            }
                        if(flag1)
                            $scope.orders.push({"OrderID":data.Orders[i].OrderID,"OrderCode":data.Orders[i].OrderCode,"PartnerID":data.Orders[i].PartnerID,"LocationName":$scope.locations[data.Orders[i].PartnerID]});                    
                    }                    

                    $scope.orderlines.length=0;
                    for(var i = 0 ; i < data.DeliveryPlanLines.length; i++)
                    {
                        for(var j=0;j<data.OrderLines.length;j++)
                            if(data.OrderLines[j].OrderLineID==data.DeliveryPlanLines[i].OrderLineID)
                            {
                                $scope.orderlines.push({"OrderLineID":data.OrderLines[j].OrderLineID, "OrderCode":data.OrderLines[j].OrderCode, "CategoryName":data.OrderLines[j].CategoryName, "OrderID":data.OrderLines[j].OrderID,"CategoryID":data.OrderLines[j].CategoryID,"Size":data.OrderLines[j].Size, "OrderQty":data.OrderLines[j].OrderQty, "OrderRemainQty":data.OrderLines[j].OrderRemainQty, "PlanQty": data.DeliveryPlanLines[i].PlanQty,"Remain": 0,"TC_TS": data.OrderLines[j].TC+ '/' + (data.DeliveryPlanLines[i].PlanQty-data.OrderLines[j].TC),"TC":data.OrderLines[j].TC});
                                break;
                            }
                    }

                    stoploading($('#content'));
                })
                .error(function (data) {
                    stoploading($('#content'));
                    service.showModal($scope, $compile, 'error', data);
                });
        };

        $scope.planQtyChange = function(id){
            $scope.orderlines[id].PlanQty=parseInt($scope.orderlines[id].PlanQty);
            if($scope.orderlines[id].PlanQty>$scope.orderlines[id].OrderRemainQty)
                $scope.orderlines[id].PlanQty=$scope.orderlines[id].OrderRemainQty;
            $scope.orderlines[id].Remain = $scope.orderlines[id].OrderRemainQty-$scope.orderlines[id].PlanQty;
            $scope.orderlines[id].TC_TS = parseInt($scope.orderlines[id].TC) +'/' + (parseInt($scope.orderlines[id].PlanQty)-parseInt($scope.orderlines[id].TC));
        }

        $scope.refresh = function () {
            $scope.load();
        };

        $scope.add = function () {
            window.location = '@Url.Action("Detail", "DeliveryPlan", new { id = String.Empty })';
        };

        $scope.check = function (id) {
            $scope.checkedObj[id] = !$scope.checkedObj[id];
        };

        $scope.checkPlanLine = function (id) {
            $scope.checkedPlanLineObj[id] = !$scope.checkedPlanLineObj[id];
        };

        $scope.setSelected = function (id) {
            service.setSelected($scope, id);
        };

        $scope.setPlanLineSelected = function (id) {
            if ($scope.checkedPlanLineList.indexOf(id) === -1)
                $scope.checkedPlanLineList.push(id);
            else
                $scope.checkedPlanLineList.pop(id);

            $scope.checkedPlanLineObj[id] = !$scope.checkedPlanLineObj[id];
        };

        $scope.rightShift = function () {
            for (var j = 0; j < $scope.checkedList.length; j++) 
                for(var i = 0; i< $scope.orders.length;i++)
                    if($scope.orders[i].OrderID==$scope.checkedList[j])
                    {
                        $scope.checkedObj[$scope.orders[i].OrderID] = !$scope.checkedObj[$scope.orders[i].OrderID];
                        $scope.orders.splice(i,1);
                    }

            for (var j = 0; j < $scope.checkedList.length; j++) {
                for (var i = 0; i < $scope.deliveryPlan.OrderLines.length; i++) {
                    if($scope.deliveryPlan.OrderLines[i].OrderID == $scope.checkedList[j])
                    {
                        var flag = false;
                        for(var k=0;k<$scope.orderlines.length;k++)
                            if($scope.orderlines[k].OrderLineID==$scope.deliveryPlan.OrderLines[i].OrderLineID) flag = true;

                        if (flag == false) $scope.orderlines.push({"OrderLineID":$scope.deliveryPlan.OrderLines[i].OrderLineID, "OrderCode":$scope.deliveryPlan.OrderLines[i].OrderCode, "CategoryName":$scope.deliveryPlan.OrderLines[i].CategoryName, "OrderID":$scope.deliveryPlan.OrderLines[i].OrderID,"CategoryID":$scope.deliveryPlan.OrderLines[i].CategoryID,"Size":$scope.deliveryPlan.OrderLines[i].Size, "OrderQty":$scope.deliveryPlan.OrderLines[i].OrderQty, "OrderRemainQty":$scope.deliveryPlan.OrderLines[i].OrderRemainQty, "PlanQty": $scope.deliveryPlan.OrderLines[i].OrderRemainQty,"Remain": 0,"TC_TS": $scope.deliveryPlan.OrderLines[i].TC+ '/' + ($scope.deliveryPlan.OrderLines[i].OrderRemainQty-$scope.deliveryPlan.OrderLines[i].TC),"TC":$scope.deliveryPlan.OrderLines[i].TC});
                    }
                }
            }
            $scope.checkedList.length=0;
        };

        $scope.leftShift = function () {
            for (var j = 0; j < $scope.checkedPlanLineList.length; j++) {
                for (var i = 0; i <  $scope.orderlines.length; i++) {
                    if($scope.orderlines[i].OrderLineID == $scope.checkedPlanLineList[j])
                    {
                        $scope.checkedPlanLineObj[$scope.orderlines[i].OrderLineID] = !$scope.checkedPlanLineObj[$scope.orderlines[i].OrderLineID];
                        $scope.orderlines.splice(i,1);             
                    }
                }
            }

            for (var j = 0; j < $scope.checkedPlanLineList.length; j++) {
               
                for (var i = 0; i < $scope.deliveryPlan.Orders.length; i++) {
                    if($scope.deliveryPlan.Orders[i].OrderID == $scope.temp[$scope.checkedPlanLineList[j]])
                    {
                        for(var k=0;k<$scope.orders.length;k++)
                            if($scope.orders[k].OrderID==$scope.deliveryPlan.Orders[i].OrderID) $scope.orders.splice(k,1); 
                        $scope.orders.push({"OrderID":$scope.deliveryPlan.Orders[i].OrderID,"OrderCode":$scope.deliveryPlan.Orders[i].OrderCode,"PartnerID":$scope.deliveryPlan.Orders[i].PartnerID,"LocationName": $scope.locations[$scope.deliveryPlan.Orders[i].PartnerID]});
                    }
                }
            }
            $scope.checkedList.length=0;
            $scope.checkedPlanLineList.length=0;
        };

        $scope.save = function () {
            if(!$scope.deliverytype && $scope.userID.value==0) service.showModal($scope, $compile, 'error', "Vui lòng chọn tài xế");
            else if(!$scope.deliverytype && $scope.licensePlate.value==0) service.showModal($scope, $compile, 'error', "Vui lòng chọn số xe");
            else if($scope.orderlines.length==0) service.showModal($scope, $compile, 'error', "Vui lòng thêm đơn hàng vào kế hoạch giao hàng");
            else if($scope.form.$valid)
            {
                if($scope.deliverytype) 
                {
                    $scope.deliveryPlan.DeliveryType = "IN";
                    $scope.deliveryPlan.Status = $scope.status.value;
                    $scope.deliveryPlan.UserID = 0;
                    $scope.deliveryPlan.BocXep1 = 0;
                    $scope.deliveryPlan.BocXep2 = 0;
                    $scope.deliveryPlan.BocXep3 = 0;
                    $scope.deliveryPlan.LicensePlate = 0;
                    $scope.deliveryPlan.Date = $filter('date')(Date.parse($scope.deliveryPlan.Date), 'y/MM/dd');
                }
                else 
                {
                    $scope.deliveryPlan.DeliveryType = "SO";
                    $scope.deliveryPlan.Status = $scope.status.value;
                    $scope.deliveryPlan.UserID = $scope.userID.value;
                    $scope.deliveryPlan.BocXep1 = $scope.bocxep1.value;
                    $scope.deliveryPlan.BocXep2 = $scope.bocxep2.value;
                    $scope.deliveryPlan.BocXep3 = $scope.bocxep3.value;
                    $scope.deliveryPlan.LicensePlate = $scope.licensePlate.value;
                    $scope.deliveryPlan.Date = $filter('date')(Date.parse($scope.deliveryPlan.Date), 'y/MM/dd');
                }
                $scope.deliveryPlan.DeliveryPlanLines.length=0;
                for (var i = 0; i < $scope.orderlines.length; i++) {
                    var item=$scope.orderlines[i];
                    $scope.deliveryPlan.DeliveryPlanLines.push({"OrderLineID":item.OrderLineID,"PlanQty":item.PlanQty});
                }
                var url = '@url' + '@Url.Action("DeliveryPlanApi", "Api")';
                $http.put(url, $scope.deliveryPlan)
                    .success(function(data) {
                        if (@Model === 0) {
                            window.location = '@Url.Action("Detail", "DeliveryPlan")/' + data.DeliveryPlanID;
                        }
                        $scope.deliveryPlan = data;
                        stoploading($('#content'));
                        service.showModal($scope, $compile, 'notify', 'Dữ liệu đã được lưu thành công!!!');
                    })
                    .error(function(data) {
                        stoploading($('#content'));
                        service.showModal($scope, $compile, 'error', data);
                    });
            } else service.showModal($scope, $compile, 'error', "Vui lòng nhập đầy đủ thông tin");
        };

        $scope.confirmDelete = function () {
            service.showModal($scope, $compile, 'confirm', 'Bạn có chắc chắn muốn xóa dữ liệu?', 'delete()');
        };

        $scope.delete = function () {
            var url = '@url' + '@Url.Action("DeliveryPlanApi", "Api")';
            $http.delete(url, {
                params: {
                    id: $scope.deliveryPlan.DeliveryPlanID
                }
            }).success(function (data) {
                stoploading($('#content'));
                window.location = '@Url.Action("Detail", "DeliveryPlan", new { id = String.Empty })';
            }).error(function (data) {
                stoploading($('#content'));
                service.showModal($scope, $compile, 'error', data);
            });
        };

        $scope.back = function () {
            window.location = '@Url.Action("Index", "DeliveryPlan")';
        };

        $scope.statuslist = [
            { name: 'Mới', value: 'N' },
            { name: 'Đã Điều Xe', value: 'I' },
            { name: 'Hoàn Thành', value: 'C' },
        ];

        $scope.sizes = [{}];
        $scope.sizes['L'] = 'Lớn';
        $scope.sizes['N'] = 'Nhỏ';

        $scope.checkedObj = [{}];
        $scope.checkedList = [];
        $scope.checkedPlanLineObj = [{}];
        $scope.checkedPlanLineList = [];

        $scope.orders = [{}];
        $scope.partners = [{}];
        $scope.locations = [{}];
        $scope.users = [{}]; 
        $scope.bocxeps = [{}]; 
        $scope.licensePlates = [{}];
        $scope.orderlines = [{}];            
        $scope.temp = [{}];
        $scope.deliveryplanlines = [{}];
        $scope.disabled = true;
        $scope.deliverytype = false;

        $scope.loadPartner();
        $scope.loadBocXep();
        $scope.loadTaiXe();
        $scope.loadlicensePlate();
        $scope.load();
    });

    $(function () {
        $("[data-toggle=tooltip]").tooltip();
    });
</script>

<div ng-controller="DeliveryPlanController">
    @Html.Partial("_PageHeader")
    @Html.Partial("_ToolbarDetail")
    <div id="content" class="content row">
        <form role="form" name="form" autocomplete="off">
            <div class="panel-body">
                <div class="col-lg-2" style="clear: both">
                    @Html.Partial("Control/_Control_TextBox_Disabled", new Dictionary<string, string>
                    {
                        {"Text", "Số kế hoạch"},
                        {"Model", "deliveryPlan.DeliveryPlanCode"},
                        {"Name", "deliveryPlanCode"},
                    })
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_Datepicker", new Dictionary<string, string>
                    {
                        {"Text", "Ngày giao"},
                        {"Model", "deliveryPlan.Date"},
                        {"Name", "date"},
                        {"Disabled","isDisabled"}
                    })
                </div>
                <div class="col-lg-4">
                    @Html.Partial("Control/_Control_CheckBox", new Dictionary<string, string>
                    {
                        {"Text", "Khách hàng nhận tại kho"},
                        {"Model", "deliverytype"}
                    })
                </div>
                <div class="col-lg-2" style="clear: both">
                    @if (canEdit)
                    {
                        @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                        {
                            {"Text", "Tài xế"},
                            {"Model", "userID"},
                            {"Name", "userID"},
                            {"Options", "userID.name for userID in users track by userID.value"},
                            {"Disabled","deliverytype"}
                        });
                    }
                    else
                    {
                        @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                        {
                            {"Text", "Tài xế"},
                            {"Model", "userID"},
                            {"Name", "userID"},
                            {"Options", "userID.name for userID in users track by userID.value"},
                            {"Disabled","isDisabled"}

                        });
                    }
                </div>
                <div class="col-lg-2">
                    @if (canEdit)
                    {
                        @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                        {
                            {"Text", "Bốc xếp 1"},
                            {"Model", "bocxep1"},
                            {"Name", "bocxep1"},
                            {"Options", "bocxep1.name for bocxep1 in bocxeps track by bocxep1.value"},
                            {"Disabled","deliverytype"}
                        });
                    }
                    else
                    {
                        @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                        {
                            {"Text", "Bốc xếp 1"},
                            {"Model", "bocxep1"},
                            {"Name", "bocxep1"},
                            {"Options", "bocxep1.name for bocxep1 in bocxeps track by bocxep1.value"},
                            {"Disabled","isDisabled"}
                        });
                    }
                </div>
                <div class="col-lg-2">
                    @if (canEdit)
                    {
                        @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                        {
                            {"Text", "Bốc xếp 2"},
                            {"Model", "bocxep2"},
                            {"Name", "bocxep2"},
                            {"Options", "bocxep2.name for bocxep2 in bocxeps track by bocxep2.value"},
                            {"Disabled","deliverytype"}
                        });
                    }
                    else
                    {
                        @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                        {
                            {"Text", "Bốc xếp 2"},
                            {"Model", "bocxep2"},
                            {"Name", "bocxep2"},
                            {"Options", "bocxep2.name for bocxep2 in bocxeps track by bocxep2.value"},
                            {"Disabled","isDisabled"}
                        });
                    }
                </div>
                <div class="col-lg-2">
                    @if (canEdit)
                    {
                        @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                        {
                            {"Text", "Bốc xếp 3"},
                            {"Model", "bocxep3"},
                            {"Name", "bocxep3"},
                            {"Options", "bocxep3.name for bocxep3 in bocxeps track by bocxep3.value"},
                            {"Disabled","deliverytype"}
                        });
                    }
                    else
                    {
                        @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                        {
                            {"Text", "Bốc xếp 3"},
                            {"Model", "bocxep3"},
                            {"Name", "bocxep3"},
                            {"Options", "bocxep3.name for bocxep3 in bocxeps track by bocxep3.value"},
                            {"Disabled","isDisabled"}
                        });
                    }
                </div>
                <div class="col-lg-2" style="clear: both">
                    @if (canEdit)
                    {
                        @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                        {
                            {"Text", "Số xe"},
                            {"Model", "licensePlate"},
                            {"Name", "licensePlate"},
                            {"Options", "licensePlate.name for licensePlate in licensePlates track by licensePlate.value"},
                            {"Disabled","deliverytype"}
                        });
                    }
                    else
                    {
                        @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                        {
                            {"Text", "Số xe"},
                            {"Model", "licensePlate"},
                            {"Name", "licensePlate"},
                            {"Options", "licensePlate.name for licensePlate in licensePlates track by licensePlate.value"},
                            {"Disabled","isDisabled"}
                        });
                    }
                </div>
                <div class="col-lg-2">
                    @Html.Partial("Control/_Control_ComboBox", new Dictionary<string, string>
                    {
                        {"Text", "Tình trạng"},
                        {"Model", "status"},
                        {"Name", "status"},
                        {"Options", "status.name for status in statuslist track by status.value"},
                        {"Disabled","disabled"}
                    })
                </div>
                <div class="col-lg-8" style="clear: both">
                    @Html.Partial("Control/_Control_TextArea", new Dictionary<string, string>
                    {
                        {"Text", "Ghi chú"},
                        {"Model", "deliveryPlan.Description"},
                        {"Name", "description"},
                        {"Disabled","isDisabled"}
                    })
                </div>
                @if (canEdit)
                {                    
                    <div class="col-lg-8" style="clear: both; border-top: 1px solid lightgray; margin-top: 10px; margin-bottom: 10px">
                    </div>
                    <div class="col-lg-5" style="clear: both">
                        <b>Đơn hàng chưa hoàn thành</b>
                    </div>
                    <div class="col-lg-4">
                        <b>Hàng sẽ giao</b>
                    </div>
                }
                else
                {
                    <div class="col-lg-5" style="clear: both">
                        <b>Danh sách hàng giao theo kế hoạch</b>
                    </div>
                }

                @if (canEdit)
                {
                    <div class="col-lg-4" style="clear: both">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <colgroup>
                                    <col style="width: 10px" />
                                    <col />
                                    <col style="width: 100px" />
                                    <col />
                                </colgroup>
                                <thead>
                                    <tr>
                                        <th>#
                                        </th>                                        
                                        <th>Đơn hàng
                                        </th>
                                        <th>Khách hàng
                                        </th>
                                        <th>Khu Vực
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr ng-repeat="item in orders" ng-click="setSelected(item.OrderID)">
                                        <td class="center">
                                            <input ng-click="check(item.OrderID)" ng-model="checkedObj[item.OrderID]" type="checkbox" /></td>
                                        <td>{{item.OrderCode}}</td>
                                        <td>{{partners[item.PartnerID]}}</td>
                                        <td>{{item.LocationName}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="col-lg-1">
                        <br></br>
                        <button class="btn btn-primary btn-sm" type="button" ng-click="rightShift()">
                            <i class="fa fa-forward fa-fw"></i>
                        </button>
                        <br></br>
                        <button class="btn btn-primary btn-sm" type="button" ng-click="leftShift()">
                            <i class="fa fa-backward fa-fw"></i>
                        </button>
                    </div>
                    <div class="col-lg-7">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <colgroup>
                                    <col style="width: 10px" />
                                    <col />
                                    <col style="width: 50px" />
                                    <col style="width: 50px" />
                                    <col style="width: 70px" />
                                    <col style="width: 70px" />
                                    <col style="width: 50px" />
                                    <col style="width: 50px" />
                                    <col style="width: 60px" />
                                </colgroup>
                                <thead>
                                    <tr>
                                        <th>#
                                        </th>
                                        <th>MS ĐH
                                        </th>
                                        <th>Chai
                                        </th>
                                        <th>K.Thước
                                        </th>
                                        <th>SL đặt
                                        </th>
                                        <th>SL chưa lập KH
                                        </th>
                                        <th>SL Giao
                                        </th>
                                        <th>Còn lại
                                        </th>
                                        <th>TC/TS
                                        </th>
                                </thead>
                                <tbody>
                                    <tr ng-repeat="item in orderlines" ng-click="setPlanLineSelected(item.OrderLineID)">
                                        <td class="center">
                                            <input ng-click="checkPlanLine(item.OrderLineID)" ng-model="checkedPlanLineObj[item.OrderLineID]" type="checkbox" /></td>
                                        <td>{{item.OrderCode}}</td>
                                        <td>{{item.CategoryName}}</td>
                                        <td>{{sizes[item.Size]}}</td>
                                        <td>{{item.OrderQty}}</td>
                                        <td>{{item.OrderRemainQty}}</td>
                                        <td>
                                            <div class="form-group">
                                                <input ng-model="item.PlanQty" name="planQty{{$index}}" type="text" class="form-control" ng-change="planQtyChange($index)" ng-maxlength="2" ng-pattern="/^[0-9., ]+$/" ng-disabled="isDisabled" />
                                                <div class="error-container"
                                                    ng-show="form.planQty{{$index}}.$dirty && form.planQty{{$index}}.$invalid">
                                                    <small class="error"
                                                        ng-show="form.planQty{{$index}}.$error.maxlength">
                                                        <p style="color: red"><b>Tối đa 2 ký tự</b></p>
                                                    </small>
                                                    <small class="error"
                                                        ng-show="form.planQty{{$index}}.$error.pattern">
                                                        <p style="color: red"><b>Ký tự không hợp lệ</b></p>
                                                    </small>
                                                </div>
                                            </div>
                                        </td>
                                        <td>{{item.Remain}}</td>
                                        <td>{{item.TC_TS}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                }
                else
                {
                    <div class="col-lg-7" style="clear: both">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <colgroup>
                                    <col style="width: 10px" />
                                    <col />
                                    <col style="width: 50px" />
                                    <col style="width: 50px" />
                                    <col style="width: 70px" />
                                    <col style="width: 80px" />
                                    <col style="width: 80px" />
                                    <col style="width: 50px" />
                                </colgroup>
                                <thead>
                                    <tr>
                                        <th>#
                                        </th>
                                        <th>MS Đơn Hàng
                                        </th>
                                        <th>Chai
                                        </th>
                                        <th>K.Thước
                                        </th>
                                        <th>SL đặt
                                        </th>
                                        <th>SL Giao
                                        </th>
                                        <th>Còn lại
                                        </th>
                                        <th>TC/TS
                                        </th>
                                </thead>
                                <tbody>
                                    <tr ng-repeat="item in orderlines" ng-click="setPlanLineSelected(item.OrderLineID)">
                                        <td class="center">
                                            <input ng-click="checkPlanLine(item.OrderLineID)" ng-model="checkedPlanLineObj[item.OrderLineID]" type="checkbox" /></td>
                                        <td>{{item.OrderCode}}</td>
                                        <td>{{item.CategoryName}}</td>
                                        <td>{{sizes[item.Size]}}</td>
                                        <td>{{item.OrderQty}}</td>
                                        <td>
                                            <div class="form-group">
                                                <input ng-model="item.PlanQty" name="planQty{{$index}}" type="text" class="form-control" ng-change="planQtyChange($index)" ng-maxlength="2" ng-pattern="/^[0-9., ]+$/" ng-disabled="isDisabled" />
                                                <div class="error-container"
                                                    ng-show="form.planQty{{$index}}.$dirty && form.planQty{{$index}}.$invalid">
                                                    <small class="error"
                                                        ng-show="form.planQty{{$index}}.$error.maxlength">
                                                        <p style="color: red"><b>Tối đa 2 ký tự</b></p>
                                                    </small>
                                                    <small class="error"
                                                        ng-show="form.planQty{{$index}}.$error.pattern">
                                                        <p style="color: red"><b>Ký tự không hợp lệ</b></p>
                                                    </small>
                                                </div>
                                            </div>
                                        </td>
                                        <td>{{item.Remain}}</td>
                                        <td>{{item.TC_TS}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                }
            </div>
        </form>
    </div>
</div>
